<template>
	<view>
		<up-navbar leftIconColor="#FFFFFF" leftIconSize="44rpx" title="历史投稿" :autoBack="true" placeholder
			bgColor="transparent">
		</up-navbar>
		<up-empty v-if="result.list.length === 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png">
		</up-empty>
		<view v-for="item in result.list" :key="item.id" style="margin: 30rpx auto 0;width: 690rpx;">
			<deaftIndex :item="item" @click="details(item)" />
		</view>

		<up-back-top :scrollTop="scrollTop" :iconStyle="iconStyle" :duration="200" :bottom="20"></up-back-top>
		<up-gap height="160rpx"></up-gap>
	</view>
</template>

<script setup>
	import deaftIndex from "@/components/draft/index.vue"
	import openApi from "@/api/biz/open";
	import {
		ref,
		reactive
	} from "vue"
	import {
		onPageScroll,
		onLoad,
		onReachBottom
	} from "@dcloudio/uni-app"

	const iconStyle = {
		fontSize: '32rpx',
		color: '#2979ff'
	};
	const scrollTop = ref(0);
	onPageScroll((e) => {
		scrollTop.value = e.scrollTop;
	})

	onReachBottom(() => {
		if (result.list.length >= result.total) return;
		params.pageNo++;
		page()
	})

	const result = reactive({
		list: [],
		total: 0
	})
	const params = reactive({
		pageNo: 1
	})

	function page() {
		const userInfo = uni.getStorageSync("userInfo")
		openApi.getStrategyPage({
			pageNo: params.pageNo,
			pageSize: 10,
			userId: userInfo.id,
			type: 2
		}).then((res) => {
			if (res.code === 0) {
				result.total = res.data.total;
				if (params.pageNo === 1) result.list = res.data.list;
				else result.list = result.list.concat(res.data.list)
			}
		})
	}

	onLoad(() => {
		page()
	})
</script>

<style>
	page {
		background-color: #1B1829;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 30rpx;
		color: #fff;
	}
</style>